package cn.itsource.pethome.basic.service.impl;

import cn.itsource.pethome.basic.mapper.BaseMapper;
import cn.itsource.pethome.basic.query.BaseQuery;
import cn.itsource.pethome.basic.service.IBaseService;
import cn.itsource.pethome.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * @Title: ${file_name}
 * @Package:${package_name}
 * @Description:(作用)
 * @author:chenhang
 * @date:${date}
 * @version:V1.0
 */
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;

    /*添加数据*/
    @Override
    @Transactional
    public void save(T t) {
        baseMapper.save(t);
    }
    /*修改数据*/
    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);
    }
    /*根据id删除*/
    @Override
    @Transactional
    public void delete(Long id) {
        baseMapper.delete(id);
    }
    /*批量删除*/
    @Override
    @Transactional
    public void patchDelete(List<Long> ids) {
        baseMapper.patchDelete(ids);
    }
    /*查询单个数据*/
    @Override
    public T findById(Long id) {
        return baseMapper.findById(id);
    }

    /*查询所有数据*/
    @Override
    public List<T> findAll() {
        return baseMapper.findAll();
    }

    /*分页条件查询*/
    @Override
    public PageList<T> findPageByQuery(BaseQuery query) {
        //获取总条数
        Long total = baseMapper.findCountByQuery(query);
        if (total.equals(0L)){
            return new PageList<T>();
        }
        //获取对象参数
        List<T> result = baseMapper.findListByQuery(query);
        return new PageList<T>(result,total);
    }


}
